import { _decorator, Component, EditBox, Node } from "cc";
import EventManager from "../manages/EventManager";
import { EventEnum } from "../Enum";
import { ConnectionManager } from "../manages/ConnectionManger";

const { ccclass, property } = _decorator;
@ccclass('LoginManager')
export class LoginManager extends Component {

    username: Node;
    password: Node;
    loginBtn: Node;

    onLoad() {
        this.username = this.node.getChildByName("username")
        this.password = this.node.getChildByName("password")
        this.loginBtn = this.node.getChildByName("loginBtn")

        
        ConnectionManager.Instance.connect()

        // EventManager.Instance.on(EventEnum.Login, this.loginHandle, this)
    }

    loginHandle() {

        const username = this.username.getComponent(EditBox).string
        const password = this.password.getComponent(EditBox).string

        ConnectionManager.Instance.send({
            url: 'login',
            data: {
                username, password
            }
        })

    }

    onDestroy() {
        // EventManager.Instance.off(EventEnum.Login, this.loginHandle, this)
    }




}

